package com.glela.order.service.impl.vo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections4.CollectionUtils;

import com.glela.goods.model.vo.InventoryVo;
import com.glela.order.model.OrderDetail;

public class OrderAddParamsVo extends OrderVo {
	private int								totalQuantity;
	private Map<Integer, List<OrderDetail>>	storeOrderDetails	= new HashMap<>();

	public OrderAddParamsVo(long userId) {
		super(userId);
	}

	public void setValue(int salePrice, int settlementPrice, int quantity, int storeId, int selfSupport, long goodsId, int brandId, OrderDetail orderDetail, InventoryVo inventory) {
		setValue(salePrice * quantity, storeId, selfSupport, goodsId, brandId, orderDetail.getIsOpenStoreGoods() == 1);
		totalQuantity += quantity;
		//		orderDetail.setSalePrice(salePrice);
		orderDetail.setSettlementPrice(inventory.getSettlementPrice());
		orderDetail.setTotalSettlementprice(orderDetail.getQuantity().intValue() * orderDetail.getSettlementPrice());
		if (CollectionUtils.isEmpty(storeOrderDetails.get(storeId))) {
			storeOrderDetails.put(storeId, new ArrayList<OrderDetail>());
		}
		storeOrderDetails.get(storeId).add(orderDetail);
	}

	@Override
	public void clear() {
		super.clear();
		totalQuantity = 0;
		getStoreOrderDetails().clear();
	}

	public int getTotalQuantity() {
		return totalQuantity;
	}

	public Map<Integer, List<OrderDetail>> getStoreOrderDetails() {
		return storeOrderDetails;
	}

	public List<OrderDetail> getStoreOrderDetails(int storeId) {
		if (CollectionUtils.isEmpty(getStoreOrderDetails().get(storeId))) {
			getStoreOrderDetails().put(storeId, new LinkedList<OrderDetail>());
		}
		return getStoreOrderDetails().get(storeId);
	}

}
